/* eslint-disable no-unused-vars */
import {
	log
} from '@/common/utils'
export default {
	data: function() {
		return {
			pageData:[],
			total: 0,
			isHasNextPage: true,
			Loading: 'loadmore',
		};
	},
	methods: {
		async refresh(isReach = false){
			try {
				let res = await this[this.pageApi](this.queryParams)
				if(isReach){
					this.pageData = [...this.pageData, ...res.list]
				}else{
					this.pageData = res.list
				}
				this.total = res.total
				this.Loading = 'loadmore'
				uni.stopPullDownRefresh();
			}catch(e){
				log(e)
			}
		},
		 resetPageAndRefresh() {
			this.isHasNextPage = true
			this.queryParams.pageNum = 1;
			this.refresh();
		},
		getNextPageData(){
			if(!this.isHasNextPage) return this.Loading = 'nomore';
			// if((this.queryParams.pageNum + 1) * this.queryParams.pageSize > this.total){
			if((this.queryParams.pageNum) * this.queryParams.pageSize > this.total){
				// uni.$u.toast('无更多数据')
				this.Loading = 'nomore'
				this.isHasNextPage = false
				return;
			}
			this.queryParams.pageNum += 1
			this.Loading = 'loading'
			this.refresh(true)
		}
	}
};
